﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form4 : Form
    {
        public string myname = "";
        public Form4(string name)
        {
            myname = name;
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string type = "";
            if (radioButton1.Checked)
            {
                type = radioButton1.Tag.ToString();
            }
            else if (radioButton2.Checked)
            {
                type = radioButton2.Tag.ToString();
            }

            Mydb mydb = new Mydb();
            if (myname == "")
            {
                mydb.insertProblemType(name, type);
            }
            else 
            {
                mydb.updateProblemType(myname,name);
            }
            mydb.coleconn();
            this.Close();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterScreen; 
            if (myname != "")
            {
                Mydb mydb = new Mydb();
                DataTable dt = mydb.getProblemType(myname);
                mydb.coleconn();
                this.textBox1.Text = dt.Rows[0]["G_name"].ToString();
                string type = dt.Rows[0]["G_sorting"].ToString();
                if (type == "0")
                {
                    radioButton1.Checked = true;
                }
                else if (type == "1")
                {
                    radioButton2.Checked = true;
                }
                button1.Text = "修改";
                this.Text = "修改类型";
            }
            
        }

        private void Form4_Activated(object sender, EventArgs e)
        {
            textBox1.Focus();
        }


        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {

            int WM_KEYDOWN = 256;

            int WM_SYSKEYDOWN = 260;

            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
            {
                switch (keyData)
                {
                    case Keys.Escape:
                        this.Close();//esc关闭窗体
                        break;
                }
            }
            return false;
        }

    }
}
